# -*- coding : utf_8 -*-
"""
=======================================
Time : 2025/4/15 20:57
Author : 田霄汉
Email : 522989570@qq.com
File : get_random.py
Project : pandas_demo
=======================================
"""
import random


class GetRandom:
    """
    获取各种随机数据
    """
    def get_random_data(self, n):
        """
        获取n位的随机数据,数据中最少包含1位大写字母,小写字母和数字
        :param n: n表示位数,需要大于等于3
        :return:
        """
        try:
            WORD_n = random.randint(1, 8)
            word_n = random.randint(1, n-WORD_n-1)
            Num_n = n-WORD_n-word_n

            WORD = random.choices('ABCDEFGHIJKLMNOPQRSTUVWSYZ', k=WORD_n)
            word = random.choices('abcdefghijklmnopqrstuvwsyz', k=word_n)
            Num = random.choices('1234567890', k=Num_n)

            result_list = WORD+word+Num
            random.shuffle(result_list)

            result = ''
            for i in result_list:
                result += i
            return result
        except Exception as e:
            print(f'报错信息: {e}')

    def get_random_float(self, min_num, max_num):
        """
        获取一定范围区间的随机浮点数
        :param min_num: 最小正整数
        :param max_num: 最大正整数
        :return:
        """
        try:
            random_str = format(random.randint(min_num, max_num-1)+random.random(), '.2f')
            random_float = float(random_str)
            return random_float

        except Exception as e:
            print(f'报错信息: {e}')
